﻿// --------------------------------------------------------------------------------------------------------------------- 
// <copyright file="IntegrationTestBase.cs" company="">
//   
// </copyright>
// <summary>
//   Defines the IntegrationTestBase type.
// </summary>
// ---------------------------------------------------------------------------------------------------------------------
using System.Configuration;

namespace Facebook.Integration.Test
{
    using Facebook.Core.Contracts;
    using Facebook.Fluent;
    using MbUnit.Framework;

    /// <summary>
    /// Base class for integration tests.
    /// </summary>
    public class IntegrationTestBase
    {
        /// <summary>
        /// Initialise facebook service for web integration tests.
        /// </summary>
        private IFacebookService facebookService;

        /// <summary>
        /// Gets the facebook service.
        /// </summary>
        /// <value>The facebook service.</value>
        protected IFacebookService FacebookService
        {
            get { return this.facebookService; }
        }

        /// <summary>
        /// Setups data for tests.
        /// </summary>
        [SetUp]
        public void TestSetup()
        {
            if (this.facebookService == null)
            {
                this.facebookService =
                    FB.For(ConfigurationManager.AppSettings["apiKey"], ConfigurationManager.AppSettings["secretKey"])
                        .With(new FacebookSessionManager())
                        .Build;
            }

            this.OnTestInitialise();
        }

        /// <summary>
        /// Cleans up test data.
        /// </summary>
        [TearDown]
        public void Cleanup()
        {
            this.OnTestCleanup();
        }

        /// <summary>
        /// Called when [test initialise].
        /// </summary>
        protected virtual void OnTestInitialise()
        {
        }

        /// <summary>
        /// Called when [test cleanup].
        /// </summary>
        protected virtual void OnTestCleanup()
        {
        }
    }
}
